<?php

class UserMenu extends Portlet
{
    // {{{ init
    public function init()
    {
        if(isset($_POST['command']) && $_POST['command']==='logout')
        {
            Yii::app()->user->logout();
            $this->controller->redirect(Yii::app()->homeUrl);
        }
	$user = User::model()->findByPK(Yii::app()->user->id);
 	if(is_null($user)) {
	    $userName = _('Guest');
	} else {
	    $userName = sprintf(
		"%s.%s",
		substr($user->firstName,0,1),
		$user->lastName
	    );
	}
        $this->title=CHtml::encode(Yii::t('site','User: {userName}',array('{userName}'=>$userName)));
        parent::init();
    } // }}} 
    // {{{ renderContent
    protected function renderContent()
    {
	$this->render(
	    'userMenu',
	    array(
		'currentLang' => Yii::app()->language
	    )
	);
    } // }}} 
}
